// pages/self/pastAppointment/pastAppointment.js
var app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    classfiySelect:"",
      doctorId:"",
      unitphone:"",
      fieldid:"",
      rigId:'01',
      leftText: [{
        id: "01",
        office: "已就诊",
      },
      {
        id: "02",
        office: "未就诊",
      },
      {
        id: "03",
        office: "已逾期",
      },],
      rightData: [{
        id: "01",
        title:"已就诊",
        frist: [/*{
          url: "/pages/images/8.png",
          doctorname: "张医生",
          doctortitle: "特邀专家",
          doctorid:"10",          
          clinicType:'01'
        },
        {
          url: "/pages/images/8.png",
          doctorname: "张医生",
          doctortitle: "特邀专家",
          doctorid:"20",
          clinicType:'01'
        },
        {
          url: "/pages/images/8.png",
          doctorname: "张医生",
          doctortitle: "特邀专家",
          doctorid:"10",
          clinicType:'01',
          times:"2020-12-1"
        },
        {
          url: "/pages/images/8.png",
          doctorname: "张医生",
          doctortitle: "特邀专家",
          doctorid:"20",
          clinicType:'01'
        },
        {
          url: "/pages/images/8.png",
          doctorname: "张医生",
          doctortitle: "特邀专家",
          doctorid:"10",
          clinicType:'01'
        },
        {
          url: "/pages/images/8.png",
          doctorname: "张医生",
          doctortitle: "特邀专家",
          doctorid:"20",
          clinicType:'01'
        }*/
      ],
      },
      {
        id: "02",
        title:"未就诊",
        frist: [
          /*{
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"10",
            clinicType:'02'
          },
          {
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"20",
            clinicType:'02'
          },
          {
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"10",
            clinicType:'02'
          },
          {
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"20",
            clinicType:'02'
          },
          {
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"10",
            clinicType:'02'
          },
          {
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"20",
            clinicType:'02'
          }*/
        ],
      },
      {
        id: "03",
        title:"已逾期",
        frist: [
          /*{
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"10",
            clinicType:'03'
          },
          {
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"20"
          },
          {
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"10"
          },
          {
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"20"
          },
          {
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"10"
          },
          {
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"20"
          }*/
        ],
      },
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      classfiySelect: this.data.leftText[0].id,
    })
    console.log(getApp().globalData.doctorId)
    var that = this;
    wx.request({
      url:  getApp().globalData.url+'patientmedicalrecordbydoctor', // 仅为示例，并非真实的接口地址
      method: 'GET',
      data: {
          doctorId:getApp().globalData.doctorId,
          unitphone:getApp().globalData.unitphone
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      success(res) {  
        console.log(res.data)
        let fi={};
        let first1=[];
        let first2=[];
        let first3=[];
        var today = new Date();
        today = today.toISOString().slice(0,10)
        console.log("今天日期")
        console.log(today)
          for(let i=0;i<res.data.length;i++)
          {
            
              var doctorId0="";
              var doctorRank0="";
              var doctorName0 ="";
              var photoUrl0="";
              var bookId0 ="";
              var times0="";
              var date0="";
              doctorName0=res.data[i].doctorName;
              doctorId0=res.data[i].orderForm.doctorId;
              doctorRank0=res.data[i].doctorRank;
              photoUrl0=res.data[i].doctorPhoto;
              bookId0=res.data[i].orderForm.bootId;
              times0=res.data[i].orderForm.bootDate + " "+res.data[i].orderForm.bootTime;
              var date0 = res.data[i].orderForm.bootDate;
             //fi ={"doctorname":doctorName0,"doctortitle":doctorRank0,"doctorid":doctorId0,"url":photoUrl0,"clinicType":that.data.leftText[j].id,"bookId":bookId0,"times":times0+" "+date0};        
              if(res.data[i].orderForm.progress=="已就诊")
            {
              console.log("一")
              fi ={"doctorname":doctorName0,"doctortitle":doctorRank0,"doctorid":doctorId0,"url":photoUrl0,"clinicType":that.data.leftText[0].id,"bookid":bookId0,"times":times0};        
              first1.push(fi);
            }
            else 
            {
                if(date0<today)
              {
                console.log("三")
                fi ={"doctorname":doctorName0,"doctortitle":doctorRank0,"doctorid":doctorId0,"url":photoUrl0,"clinicType":that.data.leftText[2].id,"bookid":bookId0,"times":times0};        
                first3.push(fi);
              }
              else{
                console.log("二")
                fi ={"doctorname":doctorName0,"doctortitle":doctorRank0,"doctorid":doctorId0,"url":photoUrl0,"clinicType":that.data.leftText[1].id,"bookid":bookId0,"times":times0};        
                first2.push(fi);
              }
            }
            
          }
            that.setData({
              "rightData[0].frist":first1
            })
            that.setData({
              "rightData[1].frist":first2
            })
            that.setData({
              "rightData[2].frist":first3
            })  
         console.log(res.data);
      },
      fail(res){
        wx.showToast({
          title: '网络连接失败，请重新尝试',
          icon:'none'
        })
      }
    })
  },
  scroll: function(e) {
    var scrollTop = e.detail.scrollTop,
    h = 0,
    classfiySelect;
    var that = this;
    that.data.leftText.forEach(function(clssfiy, i) {
      var _h =26 + that.length(clssfiy['id'])*102;
      if (scrollTop >= h){
        classfiySelect = clssfiy['id'];
      }
    h +=_h;
    })
    that.setData({
    classfiySelect: classfiySelect,
    })
    console.log(that.data.classfiySelect)
  },
  //求每一栏高度
  length: function(e) {
    var that = this;
    var rightData = that.data.rightData;
    for (var i = 0; i < rightData.length; i++) {
      if(rightData[i]['id']==e){
        return rightData[i]['frist'].length;
      }
    }
  },
  //点击左边事件
  left_list: function(e) {
    var that = this;
    var l_id = e.currentTarget.dataset.id;
    that.setData({
      rigId: l_id,
    })
  },
  toRecords: function(e){
    var chooseBook = e.target.dataset.index;
    console.log(chooseBook)
    app.globalData.bookId=chooseBook
    console.log(app.globalData.bookId)
    wx.navigateTo({
      url: '../medicalRecords/medicalRecords',
    })
  },

  toAppointment: function(e){
    var chooseBook = e.target.dataset.index;
    console.log(chooseBook)
    app.globalData.bookId=chooseBook
    console.log(app.globalData.bookId)
    wx.navigateTo({
      url: '../appointInformation/appointInformation',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})